package com.hushan.elevator.aspect;

import com.hushan.elevator.annotation.DeviceConfig;
import com.hushan.elevator.annotation.DeviceLog;
import com.hushan.elevator.dao.UserRepository;
import com.hushan.elevator.security.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Component
public class DeviceLogAspect {

    private final UserRepository userRepository;

    @Autowired
    private DeviceConfig config;

    public DeviceLogAspect(UserRepository userRepository) {
        this.userRepository = userRepository;
    }


    // 前置通知：在匹配的方法执行前打印日志
    @Before("@annotation(ann)")
    public void logBefore(DeviceLog ann) {
        System.out.println("tttttt");
        System.out.println(config.getDeviceId());
        System.out.println("测试" +ann.businessType());
        System.out.println(SecurityUtils.getUser());
    }


}